<?php
//session_start();
//include_once('../includes/config.php');
//include_once('checkuser.php');
//include_once('menu.php');



echo "Pacerrechner";
?>
<!DOCTYPE HTML>
<html style="margin: auto; width:800px">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Pacerechner</title>
<div >

<body>
<br />
<br />
<form method="post" action="<?php  $_SERVER['PHP_SELF'] ?>">
<div style="margin: 10px;"><label for="km">KM <input type="text" name="km" id="km" /></label></div>
<div><label for="hour">Hour <input type="text" name="hour" id="hour" value=""></label><label for="min">Min<input type="text" name="min" id="min" value=""></label><label for="sec">Sec<input type="text" name="sec" id="sec" value=""></label></div>
<div>---------</div>

<div><input type="submit" name="send" value="send">
<input type="reset"  name="cancel" value="canel"></div>
 
</form>


<?php
$km = $_POST['km'];
$hour = $_POST['hour'];
$min = $_POST['min'];
$sec = $_POST['sec'];
/*$laufzeit = 1304202864;
$laufzeit_min = date("i",1304202864)*60;
$laufzeit_sec = date("s",1304202864);

$laufzeit_sum = $laufzeit_hour+$laufzeit_min+$laufzeit_sec;
echo "laufzeitsum: ".$laufzeit_sum;
echo "<br />";
echo "<br />";
echo "laufzeit_min: ".$laufzeit_min/60;
echo "<br />";
echo "laufzeit-Sek: ".$laufzeit_sec;
*/
if ($_POST['send']) {
	// Stunden in Sekunden umrechnen 
	// Stunde * 3600	
	$hour_sec = $hour * 3600;	
	// Minuten in Sekunden umrechnen
	// Minuten * 60
	$min_sec = $min * 60;
	// Sekunden bleiben Sekunden :-)
	$sec = $sec;
	// Alle Sekunden addieren
	$sum_sec = $hour_sec+$min_sec+$sec;
	
	$pace = $sum_sec/ $km;
	$rest = $pace % 60;
	$restsekunden = $rest *60;
	
	echo "sekunden" .$sec;
	echo "<br />";
	echo "<br />";
	echo "rest ist: ". $rest."";
	echo "<br />";
	echo "Pace ist ".floor($pace/60) ." Minuten pro KM und ".$rest." Sekunden";
	echo "<br />";
	
	echo "Also schöner geschrieben: Pace ist ".floor($pace/60) .":".sprintf("%02d",$rest)."";
}

function myPace ($hour, $min, $sec, $km) {
/**
 * Liefert die Pace (Minuten pro KM) zurück 
 *
 *
 *
 */
	$hour_sec = $hour * 3600;
	$min_sec = $min * 60;
	$sec = $sec;
	$sum_sec = $hour_sec+$min_sec+$sec;
	
	$pace = $sum_sec/ $km;
	$rest = $pace % 60;
	$restsekunden = $rest *60;
	floor($pace/60) .":".sprintf("%02d",$rest);
	return;

};
//echo "ff".myPace();

?>
</div>
</body>
</body>